package com.outsourcing.bottle.adapter;

import java.util.ArrayList;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.outsourcing.bottle.R;
import com.outsourcing.bottle.ui.JavaTestActivity;

public class TestCustomAdapter extends BaseAdapter{

	private JavaTestActivity context;
	private ArrayList<ArrayList<String>> arrayList;
	
	public TestCustomAdapter(JavaTestActivity context,ArrayList<ArrayList<String>> arrayList){
		this.context = context;
		this.arrayList = arrayList;
	}
	
	@Override
	public int getCount() {
		return arrayList.size();
	}

	@Override
	public Object getItem(int position) {
		return arrayList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@SuppressWarnings("unchecked")
	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView==null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.address_fragment_listitem, null);
			holder.layout = (LinearLayout)convertView.findViewById(R.id.layout);
			holder.iView = (ImageView) convertView.findViewById(R.id.address_portrait);
			holder.rightView = (ImageView)convertView.findViewById(R.id.address_call);
			holder.textNum = (TextView)convertView.findViewById(R.id.contact_job);
			
			convertView.setTag(holder);
		}else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		ArrayList<String> item = (ArrayList<String>)getItem(position);
		
		TextView textView = null;
		holder.layout.removeAllViews();
		for (int i = 0; i < item.size(); i++) {
			textView = new TextView(context);
			textView.setText(item.get(i));
			holder.layout.addView(textView);	
		}
		
		holder.textNum.setText(item.size()+"");
		holder.iView.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
//				popupWindowMyWork.showAsDropDown(v,50,-50);
//				popupWindowMyWork.showAtLocation(v,Gravity.RIGHT|Gravity.BOTTOM, 10,10);
				
//				QuickAction3D quickAction = new QuickAction3D(context, QuickAction3D.HORIZONTAL);
				
				
//				Toast.makeText(context,"position:"+position+" item:"+getItem(position), Toast.LENGTH_SHORT).show();
			}
		});
		
		holder.rightView.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				context.refreshItem(position);
				
			}
		});
		
		return convertView;
	}
	
	class ViewHolder{
		LinearLayout layout;
		ImageView iView;
		TextView textNum;
		ImageView rightView;
	}
	
}
